package com.csy.common.domain;

import com.csy.common.constants.CommonConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@ApiModel("响应信息主体")
@Data
public class  R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("返回标记：成功标记=0，失败标记=1,警告标记=2")
    private int code;
    @ApiModelProperty("返回信息")
    private String msg;
    @ApiModelProperty("显示提示")
    private boolean showHits;
    @ApiModelProperty("数据")
    private T data;

    public static <T> R<T> ok() {
        return (R<T>) restResult((Object)null, CommonConstants.SUCCESS, (String)null, false);
    }

    public static <T> R<T> ok(T data) {
        return restResult(data, CommonConstants.SUCCESS, (String)null, false);
    }

    public static <T> R<T> ok(T data, String msg) {
        return restResult(data, CommonConstants.SUCCESS, msg, false);
    }

    public static <T> R<T> ok(T data, String msg, boolean showHits) {
        return restResult(data, CommonConstants.SUCCESS, msg, showHits);
    }

    public static <T> R<T> failed() {
        return (R<T>) restResult((Object)null, CommonConstants.FAIL, (String)null, true);
    }

    public static <T> R<T> failed(String msg) {
        return (R<T>) restResult((Object)null, CommonConstants.FAIL, msg, true);
    }

    public static <T> R<T> failed(String msg, boolean showHits) {
        return (R<T>) restResult((Object)null, CommonConstants.FAIL, msg, showHits);
    }

    public static <T> R<T> failed(T data) {
        return restResult(data, CommonConstants.FAIL, (String)null, true);
    }

    public static <T> R<T> failed(T data, boolean showHits) {
        return restResult(data, CommonConstants.FAIL, (String)null, showHits);
    }

    public static <T> R<T> failed(T data, String msg) {
        return restResult(data, CommonConstants.FAIL, msg, true);
    }

    public static <T> R<T> failed(T data, String msg, boolean showHits) {
        return restResult(data, CommonConstants.FAIL, msg, showHits);
    }

    public static <T> R<T> warning(String msg) {
        return (R<T>) restResult((Object)null, CommonConstants.WARNING, msg, true);
    }

    public static <T> R<T> warning(String msg, boolean showHits) {
        return (R<T>) restResult((Object)null, CommonConstants.WARNING, msg, showHits);
    }

    public static <T> R<T> warning(T data) {
        return restResult(data, CommonConstants.WARNING, (String)null, true);
    }

    public static <T> R<T> warning(T data, boolean showHits) {
        return restResult(data, CommonConstants.WARNING, (String)null, showHits);
    }

    public static <T> R<T> warning(T data, String msg) {
        return restResult(data, CommonConstants.WARNING, msg, true);
    }

    public static <T> R<T> warning(T data, String msg, boolean showHits) {
        return restResult(data, CommonConstants.WARNING, msg, showHits);
    }

    private static <T> R<T> restResult(T data, int code, String msg, boolean showHits) {
        R<T> apiResult = new R();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        apiResult.setShowHits(showHits);
        return apiResult;
    }

    public static <T> R.RBuilder<T> builder() {
        return new R.RBuilder();
    }

    public String toString() {
        return "R(code=" + this.getCode() + ", msg=" + this.getMsg() + ", showHits=" + this.isShowHits() + ", data=" + this.getData() + ")";
    }

    public R() {
    }

    public R(int code, String msg, boolean showHits, T data) {
        this.code = code;
        this.msg = msg;
        this.showHits = showHits;
        this.data = data;
    }

    public int getCode() {
        return this.code;
    }

    public R<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return this.msg;
    }

    public R<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public boolean isShowHits() {
        return this.showHits;
    }

    public R<T> setShowHits(boolean showHits) {
        this.showHits = showHits;
        return this;
    }

    public T getData() {
        return this.data;
    }

    public R<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static class RBuilder<T> {
        private int code;
        private String msg;
        private boolean showHits;
        private T data;

        RBuilder() {
        }

        public R.RBuilder<T> code(int code) {
            this.code = code;
            return this;
        }

        public R.RBuilder<T> msg(String msg) {
            this.msg = msg;
            return this;
        }

        public R.RBuilder<T> showHits(boolean showHits) {
            this.showHits = showHits;
            return this;
        }

        public R.RBuilder<T> data(T data) {
            this.data = data;
            return this;
        }

        public R<T> build() {
            return new R(this.code, this.msg, this.showHits, this.data);
        }

        public String toString() {
            return "R.RBuilder(code=" + this.code + ", msg=" + this.msg + ", showHits=" + this.showHits + ", data=" + this.data + ")";
        }
    }
}
